package com.ykefu.assign.domain;

import com.alibaba.fastjson.JSONObject;
import com.ykefu.assign.constant.ServerCode;

/**
 * @author likai
 * @date 2020/4/18 18:57
 * @email likai@7moor..com
 * @desc
 */
public class WebSocketServerResponseBody<T> extends BaseDomain {

    private T data;

    private Integer status;

    private String msg;

    private WebSocketServerResponseBody(T data, Integer status, String msg) {
        this.data = data;
        this.status = status;
        this.msg = msg;
    }


    public static <T> WebSocketServerResponseBody<T> buildSuccess(T data){
        return new WebSocketServerResponseBody<>(data, ServerCode.SUCCESS,null);
    }

    public static <T> WebSocketServerResponseBody<T> buildError(T data, String message, Integer status){
        return new WebSocketServerResponseBody<>(data,status,message);
    }

    public static <T> WebSocketServerResponseBody<T> buildError(T data, String message){
        return new WebSocketServerResponseBody<>(data,ServerCode.DEFAULT_ERROR,message);
    }

    public static <T> WebSocketServerResponseBody<T> buildError(String message){
        return new WebSocketServerResponseBody<>(null,ServerCode.DEFAULT_ERROR,message);
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String toJSON(){
        return JSONObject.toJSONString(this);
    }
}
